<template>
  <div class="app-container">
    <el-card class="box-card" v-if="pageType == 1">
      <!-- 搜索区域 -->
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
        <el-form-item label="出库单号" prop="transferOrderNumber">
          <el-input v-model="queryParams.transferOrderNumber" placeholder="请输入出库单号" clearable size="small" />
        </el-form-item>
        <el-form-item label="调出门仓" prop="transferOutRoomWarehouseName">
         <el-cascader
              v-model="transferOutStoreId"
              :options="storeList"
              :props="{ expandTrigger: 'hover', value: 'id', label: 'name' }"
              @change="handleTransferOutStoreChange"
              clearable
            ></el-cascader>
        </el-form-item>
         <el-form-item label="调入仓库" prop="transferInRoomWarehouseName">
         <el-cascader
              v-model="transferInStoreId"
              :options="storeList"
              :props="{ expandTrigger: 'hover', value: 'id', label: 'name' }"
              @change="handleTransferInStoreChange"
              clearable
            ></el-cascader>
        </el-form-item>
        <el-form-item label="出库状态" prop="status">
           <el-select v-model="queryParams.inOrOutWarehouseStatus" placeholder="请选择调拨状态" clearable size="small">
            <el-option v-for="item in InWarehouseTypeList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 操作按钮区域 -->
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
        </el-col>
      </el-row>

      <!-- 数据表格 -->
      <el-table v-loading="loading" :data="tableData">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="出库单号" align="center" prop="inOrOutOrderNumber" />
        <el-table-column label="调拨单号" align="center" prop="transferOrderNumber" />
        <el-table-column label="调出门仓" align="center" prop="transferOutRoomWarehouseName" />
        <el-table-column label="调入门仓" align="center" prop="transferInRoomWarehouseName" />
        <el-table-column label="商品总数量" align="center" prop="totalNumber" />
        <!-- <el-table-column label="商品总金额" align="center" prop="totalPrice" /> -->
        <el-table-column label="创建人" align="center" prop="creator" />
        <el-table-column label="出库状态" align="center" prop="inOrOutWarehouseStatus">
          <template slot-scope="scope">
            <!-- <span>{{ getInWarehouseType(scope.row.inOrOutWarehouseStatus) }}</span> -->
            <el-tag :type="getStatusType(scope.row.inOrOutWarehouseStatus)">{{ getOutWarehouseType(scope.row.inOrOutWarehouseStatus) }}</el-tag>
          </template>
          
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text"  @click="handleDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.limit"
        @pagination="getList"
      />
    </el-card>
    <el-card class="box-card" v-if="pageType == 2">
      <detail :detailData="detailData" :detailRow="detailRow" @back="handleBack" />
    </el-card>
  </div>
</template>

<script>
import { storeHouseMixin } from '@/mixins/storeHouse';
import { getInventoryTransferInOutList ,getInventoryTransferInOutInfo} from '@/api/storehouse';
import detail from './detail.vue';
export default {
  name: 'TransferReceipt',
  mixins: [storeHouseMixin],
  components: {
    detail
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询参数
     queryParams: {
        page: 1,
        limit: 10,
        inOrOutWarehouseStatus: '',
        transferOrderNumber: '',
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
         let params = {
        inOrOutWarehouseType:1,
        page: this.queryParams.page,
        limit: this.queryParams.limit,
        transferInRoomWarehouseId: this.transferInStoreId[1],
        transfeInType: this.transfeInType,
        transferOutRoomWarehouseId: this.transferOutStoreId[1],
        transferOutType: this.transferOutType,
        transferOrderNumber: this.queryParams.transferOrderNumber,
        inOrOutWarehouseStatus: this.queryParams.inOrOutWarehouseStatus,
        operateType: 1
      };
     getInventoryTransferInOutList(params).then(res => {
      this.tableData = res.list
      this.total = res.total
     })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      // TODO: 实现新增逻辑
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // TODO: 实现修改逻辑
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // TODO: 实现删除逻辑
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      // TODO: 实现详情逻辑
      this.pageType = 2
      this.detailRow = row
      getInventoryTransferInOutInfo({id: row.id}).then(res => {
        console.log(res)
        this.detailData = res.list
      })
    }
  }
}
</script>

<style scoped>
.app-container {
  padding: 20px;
}
</style> 